<?php
/**
 * Created by PhpStorm.
 * User: yuanluke
 * Date: 5/4/16
 * Time: 15:05
 */

namespace App\Http\Utils\Common;


class StringUtils {

    public static function startWith($str, $substr) {
        return strpos($str, $substr) === 0;
    }


    public static function endWith($str, $substr) {
        $length = strlen($substr);
        if($length == 0)  {
            return true;
        }
        return (substr($str, -$length) === $substr);
    }


    /**
     * 随机生成指定长度的字符串
     * @param $len
     * @return string
     */
    public static function randomString($len) {
        srand(date("s"));
        $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
        $str="";
        while(strlen($str)<$len) {
            $str.=substr($possible,(rand()%(strlen($possible))),1);
        }
        return($str);
    }
    
}